package tsinghua.smxq.mc;

import java.sql.Timestamp;

import tsinghua.smxq.ui.MCListViewListener;
import tsinghua.smxq.ui.MCMenuAdapter;
import tsinghua.smxq.ui.MCMenuView;
import android.app.Activity;
import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Button;
import android.widget.ImageButton;
import android.widget.ListView;
import android.widget.TextView;

public class ProfileActivity extends Activity {
	public MCMenuView menuView;
	private ListView menuList;
	private View RightView;
	private View[] children;
	private MCMenuAdapter menuAdapter;
	private MCListViewListener menuListener;
	TextView tvGender, tvBirthday, tvClass, tvMobilephone, tvEmail;
	ImageButton ibEdit;
	Button menuBtn;
	LayoutInflater inflater;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		inflater = LayoutInflater.from(this);

		setContentView(inflater.inflate(R.layout.menu_scroll_view, null));

		RightView = inflater.inflate(R.layout.profile_view, null);
		menuView = (MCMenuView) findViewById(R.id.mScrollView);
		menuAdapter = new MCMenuAdapter(this);

		menuList = (ListView) findViewById(R.id.menuList);
		menuListener = new MCListViewListener(this);
		menuList.setAdapter(menuAdapter);
		menuList.setOnItemClickListener(menuListener);
		menuBtn = (Button) RightView.findViewById(R.id.profile_menuBtn);
		menuBtn.setOnClickListener(new Button.OnClickListener() {

			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				ProfileActivity.this.menuView.clickMenuBtn();
			}

		});

		tvGender = (TextView) RightView.findViewById(R.id.tv_gender);
		tvBirthday = (TextView) RightView.findViewById(R.id.tv_birthday);
		tvClass = (TextView) RightView.findViewById(R.id.tv_class);
		tvMobilephone = (TextView) RightView.findViewById(R.id.tv_mobilephone);
		tvEmail = (TextView) RightView.findViewById(R.id.tv_email);

		if (Session.user.getGender() == -1) {
			tvGender.setText("未填写");
		} else if (Session.user.getGender() == 0) {
			tvGender.setText("女");

		} else {
			tvGender.setText("男");

		}

		if (Session.user.getBirthday() != null) {
			Timestamp ts = Session.user.getBirthday();
			tvBirthday.setText((1900 + ts.getYear()) + "-"
					+ (ts.getMonth() + 1) + "-" + ts.getDate());
		} else {
			tvBirthday.setText("未填写");
		}

		if (Session.user.getMobilePhone() != null
				&& Session.user.getMobilePhone().compareTo("") != 0) {
			tvMobilephone.setText(Session.user.getMobilePhone());
		} else {
			tvMobilephone.setText("未填写");
		}

		if (Session.user.getEmail() != null
				&& Session.user.getEmail().compareTo("") != 0) {
			tvEmail.setText(Session.user.getEmail());
		} else {
			tvEmail.setText("未填写");
		}

		if (Session.user.getUserClass() == -1) {
			tvClass.setText("未填写");
		} else if (Session.user.getUserClass() == 0) {
			tvClass.setText("老师");
		} else if (Session.user.getUserClass() == 1) {
			tvClass.setText("学生");
		}

		ibEdit = (ImageButton) RightView.findViewById(R.id.ib_edit);
		ibEdit.setOnClickListener(new ImageButton.OnClickListener() {

			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				ProfileActivity.this.startActivity(new Intent(
						ProfileActivity.this, UpdateProfileActivity.class));
				ProfileActivity.this.finish();
			}

		});

		View leftView = new View(this);
		children = new View[] { leftView, RightView };
		leftView.setBackgroundColor(Color.TRANSPARENT);
		this.menuView.initViews(children, this.menuBtn, this.menuList);
		this.menuView.setMenuBtn(this.menuBtn);
		MCMenuAdapter.currPosition = 0;

	}
}
